package live.zs.mongodb.controller;

import live.zs.mongodb.entity.Person;
import live.zs.mongodb.repository.PersonRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author madison
 * {@code @description}
 * {@code @date} 2023/5/2 20:50
 */
@RestController
@RequestMapping("mongodb")
public class IndexController {
    @Autowired
    private PersonRepository personRepository;

    @GetMapping("index")
    public List<Person> index() {
        return personRepository.findAll();
    }

    @PostMapping("index")
    public Person index(@RequestBody Person person) {
        return personRepository.save(person);
    }
}
